package com.hy.mydesktop.client.component.factory;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.sound.midi.MetaMessage;

import com.extjs.gxt.samples.resources.client.Resources;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.BaseListLoadResult;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoader;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.dnd.DND.Feedback;
import com.extjs.gxt.ui.client.dnd.GridDragSource;
import com.extjs.gxt.ui.client.dnd.GridDropTarget;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MenuEvent;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.BoxComponent;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.grid.GridGroupRenderer;
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.GroupColumnData;
import com.extjs.gxt.ui.client.widget.grid.GroupingView;
import com.extjs.gxt.ui.client.widget.grid.RowEditor;
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
import com.extjs.gxt.ui.client.widget.menu.Menu;
import com.extjs.gxt.ui.client.widget.menu.MenuBarItem;
import com.extjs.gxt.ui.client.widget.menu.MenuItem;
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.hy.mydesktop.client.component.event.AppEvents;
import com.hy.mydesktop.client.component.meta.AbstractComponetModelEnum;
import com.hy.mydesktop.client.component.meta.AccordionPanelModelEnum;
import com.hy.mydesktop.client.component.meta.GridColumnConfigModel;
import com.hy.mydesktop.client.component.meta.GridModelEnum;
import com.hy.mydesktop.client.component.meta.GridSetModulesEnum;
import com.hy.mydesktop.client.component.meta.ShortcutModelEnum;
import com.hy.mydesktop.client.component.mvc.event.EventStructureMetaModel;
import com.hy.mydesktop.client.mvc.core.event.manager.ComponentTrrigerTemplateUtil;
import com.hy.mydesktop.client.rpc.GreetingService;
import com.hy.mydesktop.client.rpc.GreetingServiceAsync;
import com.hy.mydesktop.client.rpc.ServiceInvoker;
import com.hy.mydesktop.client.rpc.ServiceInvokerAsync;
import com.hy.mydesktop.client.rpc.reader.GxtToSeamServiceResultGridColumnModelReader;
import com.hy.mydesktop.client.rpc.reader.GxtToSeamServiceResultListReader;
import com.hy.mydesktop.client.rpcModel.RPCBaseModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtAppEventType;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.ItemOfAssociateToWindow;
import com.hy.mydesktop.shared.persistence.domain.gxt.MyBaseModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.ComponentMetaDataConstants;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.MetaDataConstants;
import com.hy.mydesktop.shared.rpc.meta.GxtToSeamServiceParameter;
import com.hy.mydesktop.shared.rpc.meta.GxtToSeamServiceResult;
import com.hy.mydesktop.shared.rpc.util.BaseModelUtil;
import com.hy.mydesktop.shared.util.log.MyLoggerUtil;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference.Metadata;

/**
 * 
 * <ul>
 * <li>开发作者：冬超</li>
 * <li>设计日期：2010-8-30；时间：下午01:11:56</li>
 * <li>类型名称：ReorderingGridFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class GridModuleFactory {

	
	// 表格的渲染
	//private static GridCellRenderer<BaseModel> ageRender;
	//  拖动
//	private static GridDropTarget dropTarget;
	// 后天交互
	private static RpcProxy<List<BaseModel>> proxy;
	// 字段模型
	
	// 调用后台的程序
	private static GreetingServiceAsync service = GWT.create(GreetingService.class);
	//private static ServiceInvokerAsync serviceInvoker = GWT.create(ServiceInvoker.class);
	// 后台加载的数据loader
	private static ListLoader<BaseListLoadResult<BaseModel>> loader;

//	private static PagingLoader<PagingLoadResult<BaseModel>> pagingLoader;
//	private static PagingLoader<PagingLoadResult<ModelData>> pagingLoader;
	
	/**
	 * 行号
	 */
	//private static RowNumberer numberer;

	public static ContentPanel createAndConfigureGridModule(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {

		return configureGridModule(gxtComponentMetaNodeModel);

	}

	
	private static ContentPanel configureGridModule(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {

		// 面板
		ContentPanel contentPanel=null;
		//配置包含Grid的容器
		contentPanel = ContentPanelFactory.createContentPanel(gxtComponentMetaNodeModel);
		
		
		
		//创建制定类型的Grid
		Grid<ModelData> grid =null; 
//		grid=	createGridAndConfigureCoreAttributes(version, gxtComponentMetaNodeModel,contentPanel);
		
		grid =createGridAndConfigureCoreAttributes_new( gxtComponentMetaNodeModel, contentPanel);
		
//		grid.setAutoWidth(true);
		grid.setStripeRows(true);
		//grid.setHeight(100);		
	    grid.setColumnLines(true);   
	    //grid.setColumnReordering(true); 
		//grid.setAutoHeight(true);
	    
	    //配置控件的共有属性
		//grid = AbstractComponetFactory.configureAbstractComponet(grid, gxtComponentMetaNodeModel);
		
//		AbstractComponetFactory.configureGxtToSeamServiceParameterModel(grid, gxtComponentMetaNodeModel);	
		//配置Grid的特有属性
		grid= GridModuleFactory.configureAttributesOfGrid(grid, gxtComponentMetaNodeModel);

		

		return contentPanel;
	}
	
	private static Grid<ModelData> createGridAndConfigureCoreAttributes_new(GxtComponentMetaNodeModel gxtComponentMetaNodeModel, ContentPanel contentPanel) {
		//gxtComponentMetaNodeModel，可能会使contentPanel可能和grid重合，混淆
		
		GroupingStore<ModelData> groupStore;
		
		List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
		ColumnModel cm=null;
		String gridModuleTypeVersion=gxtComponentMetaNodeModel.get(ComponentMetaDataConstants.GRIDMODULE_TYPE_VERSION);
		if (gridModuleTypeVersion==null) {
			throw new RuntimeException("sssssssssssssssssssssssssssssssssssssss");
		} else if (gridModuleTypeVersion.equals(ComponentMetaDataConstants.EDITORPAGING_GRIDMODULETYPE)) {
			// 可编辑分页表格
			ListStore<ModelData> pagingStore=null;
			pagingStore =  new ListStore<ModelData>();

			final EditorGrid<ModelData> grid = new EditorGrid<ModelData>(pagingStore, new ColumnModel(new ArrayList<ColumnConfig>()));
			
			configurePagingGrid(contentPanel,grid);
			//configs = loadGridColumnModel(gxtComponentMetaNodeModel,configs,grid,version);
			configs = loadGridColumnModel_new(gxtComponentMetaNodeModel,configs,grid);
			//configs = createShowButtonForGridColumn(configs);
			//configs = createEditButtonForGridColumn(configs);
			//configs = createDelteButtonForGridColumn(configs);
			
			cm = new ColumnModel(configs);
			grid.reconfigure(pagingStore, cm);
		    //配置控件的共有属性
			AbstractComponetFactory.configureAbstractComponet(grid, gxtComponentMetaNodeModel);		
			grid.setData(ComponentMetaDataConstants.GRIDMODULE_TYPE_VERSION, ComponentMetaDataConstants.EDITORPAGING_GRIDMODULETYPE);
			contentPanel.add(grid);
			
			configurePageSizeOfPagingGrid(grid ,gxtComponentMetaNodeModel);
			
			addGridToolBar(contentPanel, grid,gxtComponentMetaNodeModel);
			
			
			
			contentPanel.add(grid);
			
			return grid;
		}else if (gridModuleTypeVersion.equals(ComponentMetaDataConstants.READONLYPAGING_GRIDMODULETYPE)) {
			// 只读分页表格
			ListStore<ModelData> pagingStore=null;
			pagingStore =  new ListStore<ModelData>();
			final Grid<ModelData> grid = new Grid<ModelData>(pagingStore, new ColumnModel(new ArrayList<ColumnConfig>()));
			configs = loadGridColumnModel_new(gxtComponentMetaNodeModel,configs,grid);			
			cm = new ColumnModel(configs);
			grid.reconfigure(pagingStore, cm);
			
			AbstractComponetFactory.configureAbstractComponet(grid, gxtComponentMetaNodeModel);		

			//grid.setData("gridType", 3);
			contentPanel.add(grid);
			
			configurePageSizeOfPagingGrid(grid ,gxtComponentMetaNodeModel);
			
			addGridToolBar(contentPanel, grid,gxtComponentMetaNodeModel);
			
			contentPanel.add(grid);
			grid.setData(ComponentMetaDataConstants.GRIDMODULE_TYPE_VERSION, ComponentMetaDataConstants.READONLYPAGING_GRIDMODULETYPE);
			
			return grid;
		}else if (gridModuleTypeVersion.equals(ComponentMetaDataConstants.COMPLEXEDITORPAGING_GRIDMODULETYPE)) {
			// 带按钮（查询、修改、删除）的可编辑分页表格
			ListStore<ModelData> pagingStore=null;
			pagingStore =  new ListStore<ModelData>();

			final Grid<ModelData> grid = new Grid<ModelData>(pagingStore, new ColumnModel(new ArrayList<ColumnConfig>()));
			setControllerMetaModleIdAndFormIdForGrid(grid,gxtComponentMetaNodeModel);
			//configurePagingGrid(contentPanel,grid);
			//configs = loadGridColumnModel(gxtComponentMetaNodeModel,configs,grid,version);
			configs = loadGridColumnModel_new(gxtComponentMetaNodeModel,configs,grid);
			configs = createShowButtonForGridColumn(configs);
			configs = createEditButtonForGridColumn(configs);
			//configs = createDelteButtonForGridColumn(configs);
			
			cm = new ColumnModel(configs);
			grid.reconfigure(pagingStore, cm);
		    //配置控件的共有属性
			AbstractComponetFactory.configureAbstractComponet(grid, gxtComponentMetaNodeModel);		
			grid.setData(ComponentMetaDataConstants.GRIDMODULE_TYPE_VERSION, ComponentMetaDataConstants.COMPLEXEDITORPAGING_GRIDMODULETYPE);
			contentPanel.add(grid);
			
			configurePageSizeOfPagingGrid(grid ,gxtComponentMetaNodeModel);
			
			addGridToolBar(contentPanel, grid,gxtComponentMetaNodeModel);
			
			
			
			contentPanel.add(grid);
			
			return grid;
		} else {
			return null;
		}
		
		
		// 可编辑的表格
		/*if (version == 1) {		
			// 表格字段集合
			ListStore<ModelData> listStore =new ListStore<ModelData>();
			//listStore = getListStore();//a example of liststore 
			final EditorGrid<ModelData> editorGrid = new EditorGrid<ModelData>(listStore, new ColumnModel(new ArrayList<ColumnConfig>()));
			configs = loadGridColumnModel(gxtComponentMetaNodeModel,configs,editorGrid,version);
			cm = new ColumnModel(configs);
			editorGrid.reconfigure(listStore, cm);
			AbstractComponetFactory.configureAbstractComponet(editorGrid, gxtComponentMetaNodeModel);		
			//getField2(configs);
			addToolBar(contentPanel, editorGrid);
			contentPanel.add(editorGrid);
			return editorGrid;
			
			
		}

		else if (version == 2) {
			// 分组表格
			//groupStore = getGroupStore(table);
			groupStore = new GroupingStore<ModelData>();
			System.err.println(configs);
			Grid<ModelData> grid = new Grid<ModelData>(groupStore, cm);
			grid.setData("gridType", 2);
			//grid.setData("groupingColumnId", XXX);其他地方实现
			contentPanel.add(grid);
			//loader.load();
			return grid;
			
		}
		
		else if (version == 5) {
			// 普通表格
			
			Grid<ModelData> grid = new Grid<ModelData>(
					null, cm);
			grid.setData("gridType", 5);
			
			addToolBar(contentPanel, grid);

			contentPanel.add(grid);

			configureRegisterEventtypes(gxtComponentMetaNodeModel, grid, version);
			
			return grid;
		} else {
			return null;
		}*/
		
	}


	private static void setControllerMetaModleIdAndFormIdForGrid(Grid<ModelData> grid,
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		String formId=gxtComponentMetaNodeModel.get(MetaDataConstants.FORM_ID);
		if (formId==null) {
			throw new RuntimeException("xxxxxxxxxxxxxx");
		} else {
			grid.setData(MetaDataConstants.FORM_ID, formId);
		}
		String controllerMetaModelId=gxtComponentMetaNodeModel.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID);
		if (gxtComponentMetaNodeModel.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID)==null) {
			throw new RuntimeException("xxxxxxxxxxxxxx");
		} else {
			grid.setData(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID, controllerMetaModelId);
		}
		
	}


	private static void configurePagingGrid(ContentPanel contentPanel,
			EditorGrid<ModelData> grid) {
		// TODO Auto-generated method stub
		
	}


	private static void configurePagingGrid() {
		// TODO Auto-generated method stub
		
	}


	private static void addGridToolBar(ContentPanel contentPanel,
			final Grid<ModelData> grid,
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		ToolBar toolBar = new ToolBar();   
	    //toolBar.getAriaSupport().setLabel("Grid Options");   
	    //toolBar.add(new Button());
	    Button add = new Button("Add a Row", Resources.ICONS.add(),new SelectionListener<ButtonEvent>() {   
	        @Override   
	        public void componentSelected(ButtonEvent ce) {   
//	          grid.getStore().insert(new BaseModel(), grid.getStore().getCount());   
	          grid.getStore().insert(new BaseModel(), 0);   
	         
	        }   
	    
	      });   
	    Button fefresh = new Button("Refresh the Grid", Resources.ICONS.plugin(),new SelectionListener<ButtonEvent>() {   
	        @Override   
	        public void componentSelected(ButtonEvent ce) {   
//	          grid.getStore().insert(new BaseModel(), grid.getStore().getCount());   
	          grid.getStore().getLoader().load();
	          MessageBox.alert("消息", "数据已经刷新 !", null);
	         
	        }   
	    
	      });  
	    Button delete = new Button("Delete a Row", Resources.ICONS.delete(),new SelectionListener<ButtonEvent>() {   
	        @Override   
	        public void componentSelected(ButtonEvent ce) {  
	        	 ce.getComponent().disable();   
	          /*grid.getStore().remove(grid.getStore().getAt(0));   
	          if (grid.getStore().getCount() == 0) {   
	            ce.getComponent().disable();   
	          }*/   
	        }   
	    
	      });   
		String gridModuleTypeVersion=gxtComponentMetaNodeModel.get(ComponentMetaDataConstants.GRIDMODULE_TYPE_VERSION);
		if (ComponentMetaDataConstants.READONLYPAGING_GRIDMODULETYPE.equals(gridModuleTypeVersion)) {
		    toolBar.add(fefresh);   
		    toolBar.add(new SeparatorToolItem());   
		    //toolBar.add(new Button("Configure", Resources.ICONS.plugin()));   
		} else {
			toolBar.add(add);   
		    toolBar.add(new SeparatorToolItem());   
		    toolBar.add(fefresh);   
		    //toolBar.add(delete);   
		    //toolBar.add(new SeparatorToolItem());   
		    //toolBar.add(new Button("Configure", Resources.ICONS.plugin()));   
		};
   
	    contentPanel.setTopComponent(toolBar);   
	    //cp.add(grid);
		
	}


	private static List<ColumnConfig> loadGridColumnModel_new(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel,
			List<ColumnConfig> configs, Grid<ModelData> grid) {
		List<ComboBox<ModelData>> comboBoxs = new LinkedList<ComboBox<ModelData>>();
		ComboBox<ModelData> comboBox =null;
		if(gxtComponentMetaNodeModel.get(ComponentMetaDataConstants.CHILDREN_ITEMS)!=null){
			//添加子控件
			 List<ItemOfAssociateToWindow> list =(List<ItemOfAssociateToWindow>)gxtComponentMetaNodeModel
			 .get(ComponentMetaDataConstants.CHILDREN_ITEMS);
			
			 for(int i=0;i<list.size();i++){	
				if (list.get(i).getItemType().equals(ComponentMetaDataConstants.COMPONENT_ITEM_TYPE)) {
	//				comboBox = SimpleComboBoxFactory.createSimpleComboBox(list.get(i));
	//				comboBox = ComboBoxFactory.createComboBox(list.get(i));
					    comboBox = ComboBoxFactory.createComboBox2(list.get(i));
					    comboBoxs.add(comboBox);
				}			 
			 }		 
		 
		}
		
		//TODO 字段加载相关
		if (gxtComponentMetaNodeModel.getGridColumnConfigModels() != null) {
			Object object = gxtComponentMetaNodeModel.getGridColumnConfigModels();
			//grid.setData("columnConfigLoad", object);
			//ModelData modelData = result.getResult();
			List<GridColumnConfigModel> baseModels = (List<GridColumnConfigModel>)object;
										
			for (GridColumnConfigModel baseModel : baseModels) {
				ColumnConfig columnConfig = new ColumnConfig();
				columnConfig.setHeader((String)baseModel.get("header"));
				//设置字段是否隐藏
				if (baseModel.get("hidden")==null||!(Boolean)baseModel.get("hidden")) {
					columnConfig.setHidden(false);
				} else {
					columnConfig.setHidden(true);
				}
//				if (baseModel.get("date")!=null&&(Boolean)baseModel.get("date")) {
				/*if (baseModel.getDate()) {
					DateField dateField = new DateField();   
				    dateField.getPropertyEditor().setFormat(DateTimeFormat.getFormat("MM/dd/y"));   				    
				    columnConfig.setEditor(new CellEditor(dateField));   
				   // column.setDateTimeFormat(DateTimeFormat..getMediumDateFormat());  
				} */
				//设置字段的宽度
				columnConfig.setWidth((Integer)baseModel.get("width"));
				//设置字段的Id
				String columnConfig_id = (String)baseModel.get("id");
				columnConfig.setId(columnConfig_id);
				String gridModuleTypeVersion=gxtComponentMetaNodeModel.get(ComponentMetaDataConstants.GRIDMODULE_TYPE_VERSION);

//				if (version==1||version==4) {
				if (ComponentMetaDataConstants.EDITOR_GRIDMODULETYPE.equals(gridModuleTypeVersion)
						||ComponentMetaDataConstants.EDITORPAGING_GRIDMODULETYPE.equals(gridModuleTypeVersion)
						||ComponentMetaDataConstants.COMPLEXEDITOR_GRIDMODULETYPE.equals(gridModuleTypeVersion)
						||ComponentMetaDataConstants.COMPLEXEDITORPAGING_GRIDMODULETYPE.equals(gridModuleTypeVersion)) {
					if (comboBoxs == null||comboBoxs.size()==0) {
						columnConfig.setEditor(new CellEditor(new TextField<String>()));
					}else {
						for (ComboBox box : comboBoxs) {
							System.err.println(box.getData("id"));
							System.err.println(columnConfig_id);
							/**
							 * 由于表格中的字段为下拉框
							 * 所以需要添加两个字段（associateColumnConfig和columnConfig），而非一个
							 * associateColumnConfig对应真正的实体类例如，position中的positionType
							 * id=columnConfig_id
							 * 
							 * columnConfig，对应position中的positionTypeForShow（只是一个字符串）
							 * id=columnConfig_id+"ForShow"
							 * 并且，关联下拉框
							 */
							if (box.getData("id").equals(columnConfig_id)) {
								
								if (columnConfig_id.indexOf((String)grid.getData("id")+".") == 0) {
									columnConfig_id = columnConfig_id.substring(((String)grid.getData("id")).length()+1);
								}
								//为与ComboBox关联的ColumnConfig，添加隐藏的ColumnConfig
								ColumnConfig associateColumnConfig = new ColumnConfig();								
								associateColumnConfig.setHidden(true);
								associateColumnConfig.setHeader(columnConfig_id);
								//例如
								//position的属性-positionType，对应positionType实体类
								associateColumnConfig.setId(columnConfig_id);
								MyLoggerUtil.printError("ssssssssssssssss", columnConfig_id);
								associateColumnConfig.setWidth(100);
								associateColumnConfig.setEditor(new CellEditor(new TextField<String>()));								
//								
								configs.add(associateColumnConfig);
								columnConfig.setId(columnConfig_id+"ForShow");
								final ComboBox<ModelData> tempComboBox = box;
								CellEditor comboBoxCellEditor = getComboBoxCellEditor(tempComboBox,grid,null);
								columnConfig.setEditor(comboBoxCellEditor);
								break;
							} else {								 
								columnConfig.setEditor(new CellEditor(new TextField<String>()));
								//throw new RuntimeException("sssssssssssssaaaaaaaaaaaaaa");
							}
						}
						
					}
					
					if (baseModel.get("date")!=null&&(Boolean)baseModel.get("date")) {
						DateField dateField = new DateField();   
					    dateField.getPropertyEditor().setFormat(DateTimeFormat.getFormat("MM/dd/y"));   				    
					    columnConfig.setEditor(new CellEditor(dateField));   
					   // column.setDateTimeFormat(DateTimeFormat..getMediumDateFormat());  
					}else if (baseModel.getDate()) {
						DateField dateField = new DateField();   
					    dateField.getPropertyEditor().setFormat(DateTimeFormat.getFormat("MM/dd/y"));   				    
					    columnConfig.setEditor(new CellEditor(dateField));   
					   // column.setDateTimeFormat(DateTimeFormat..getMediumDateFormat());  
					}
				} 
				
				configs.add(columnConfig);
			}
			
		}
		for(ColumnConfig columnConfig:configs){
			MyLoggerUtil.printError("xxxxxxxxxxxxxxxxxxxxx", columnConfig.getId()+":"+columnConfig.getHeader());
		}
		return configs;
	}


	private static Grid<ModelData> configureAttributesOfGrid(
			Grid<ModelData> grid,
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		//TODO 字段加载相关
		/*if (gxtComponentMetaNodeModel.getGridColumnConfigModels() != null) {
			List<GridColumnConfigModel> list= gxtComponentMetaNodeModel.getGridColumnConfigModels();
			Object object = list;
			grid.setData("columnConfigLoad", object);
			
		}else {
			
			if (gxtComponentMetaNodeModel.get(GridModelEnum.COLUMNCONFIGLOAD.name()
					.toLowerCase()) != null) {
				Object object = gxtComponentMetaNodeModel
						.get(GridModelEnum.COLUMNCONFIGLOAD.name().toLowerCase());
				grid.setData("columnConfigLoad", object);				
			}
		}*/
		
		//TODO 数据加载相关
		/*if (gxtComponentMetaNodeModel.get(GridModelEnum.DATALOAD.name()
				.toLowerCase()) != null) {
			Object object = gxtComponentMetaNodeModel
					.get(GridModelEnum.DATALOAD.name().toLowerCase());
			grid.setData("dataLoad", object);

		}*/
		// 高度		
		// 宽度
		
		//自动调节宽度
		/*if (gxtComponentMetaNodeModel.get(AccordionPanelModelEnum.AUTOWIDTH.name()
				.toLowerCase()) != null) {
			Object autoWidth =  gxtComponentMetaNodeModel
					.get(AccordionPanelModelEnum.AUTOWIDTH.name().toLowerCase());
			if (autoWidth instanceof Boolean) {				
				grid.setAutoWidth((Boolean)autoWidth);
			} else {

				if ("true".equals(autoWidth.toString())) {
					
					grid.setAutoWidth(true);
				} else {

					grid.setAutoWidth(false);
				}
			}

		} 
		if (gxtComponentMetaNodeModel.get(AccordionPanelModelEnum.AUTOHEIGHT.name()
				.toLowerCase()) != null) {
			Object autoHeight =  gxtComponentMetaNodeModel
					.get(AccordionPanelModelEnum.AUTOHEIGHT.name().toLowerCase());
			if (autoHeight instanceof Boolean) {				
				grid.setAutoHeight((Boolean)autoHeight);
			} else {

				if ("true".equals(autoHeight.toString())) {
					
					grid.setAutoWidth(true);
				} else {

					grid.setAutoWidth(false);
				}
			}
			

		}*/ 
		
		
		

		//设置表格加载数据时，是否显示，加载标记
		if (gxtComponentMetaNodeModel.get(ComponentMetaDataConstants.GRID_LOAD_MARK) != null) {
			
			Object loadMark =  gxtComponentMetaNodeModel
					.get(AccordionPanelModelEnum.AUTOWIDTH.name().toLowerCase());
			if (loadMark instanceof Boolean) {				
				grid.setLoadMask((Boolean)loadMark);
			} else {
				if ("false".equals(loadMark.toString())) {
					grid.setLoadMask(false);
				}
			}
		}else {
			grid.setLoadMask(true);
		}
		//设置字段宽度是否可调整
		if (gxtComponentMetaNodeModel.get(GridModelEnum.ENABLECOLUMNRESIZE
				.name().toLowerCase()) != null) {
			Boolean enableColumnResize = (Boolean) gxtComponentMetaNodeModel
					.get(GridModelEnum.ENABLECOLUMNRESIZE.name().toLowerCase());
			//grid.setEnableColumnResize(enableColumnResize);
			//grid.
		}
		//设置最小字段宽度
		if (gxtComponentMetaNodeModel.get(GridModelEnum.MINCOLUMNWIDTH.name()
				.toLowerCase()) != null) {
			Integer minColumnWidth = (Integer) gxtComponentMetaNodeModel
					.get(GridModelEnum.MINCOLUMNWIDTH.name().toLowerCase());
			grid.setMinColumnWidth(minColumnWidth);

		}
		//设置自动扩张的字段
		if (gxtComponentMetaNodeModel.get(GridModelEnum.AUTOEXPANDCOLUMN.name()
				.toLowerCase()) != null) {
			String autoColumn = (String) gxtComponentMetaNodeModel
					.get(GridModelEnum.AUTOEXPANDCOLUMN.name().toLowerCase());
			grid.setAutoExpandColumn(autoColumn);

		}
		//设置是否高亮显示，选中的数据
		if (gxtComponentMetaNodeModel.get(GridModelEnum.TRACKMOUSEOVER.name()
				.toLowerCase()) != null) {
			Boolean trackMouseOver = (Boolean) gxtComponentMetaNodeModel
					.get(GridModelEnum.TRACKMOUSEOVER.name().toLowerCase());
			grid.setTrackMouseOver(trackMouseOver);

		}
		
		
		
		//设置单元格，可编辑的样式：是行可编辑样式
		if (gxtComponentMetaNodeModel.get(GridModelEnum.ROEWEDIT.name()
				.toLowerCase()) != null) {
			RowEditor<ModelData> editor = new RowEditor<ModelData>();
			grid.addPlugin(editor);
		}
		
		
		
		/*//设置表格可拖动
		if (gxtComponentMetaNodeModel.get(GridModelEnum.REODRDER.name()
				.toLowerCase()) != null) {
			new GridDragSource(grid);
			  
			dropTarget = new GridDropTarget(grid);
			dropTarget.setAllowSelfAsSource(true);  
		}
		
		//与可拖动配合使用（见上）必须配合使用
		if (gxtComponentMetaNodeModel.get(GridModelEnum.FEEBACK.name()
				.toLowerCase()) != null) {
			//设置TreeGrid的内部结构的，拖动改变
			String back = ((String) gxtComponentMetaNodeModel
					.get(GridModelEnum.FEEBACK.name().toLowerCase()))
					.toUpperCase();
			if (back.equals("APPEND")) {
				dropTarget.setFeedback(Feedback.APPEND);
			} else if (back.equals("BOTH")) {
				dropTarget.setFeedback(Feedback.BOTH);
			} else {
				dropTarget.setFeedback(Feedback.INSERT);
			}

		}*/
		
		//是表格，可以显示行号（需要）		
		if (gxtComponentMetaNodeModel.get(GridModelEnum.ROWNUMBER.name()
				.toLowerCase()) != null) {		
				/*RowNumberer showRowNumberer = new RowNumberer();
				showRowNumberer.setWidth(20);
				configs.add(0,showRowNumberer);
				grid.addPlugin(showRowNumberer);*/
			grid.setData("showRowNumberer", true);
			
		}
						
		//分组表格的设置
		if (gxtComponentMetaNodeModel.get(GridModelEnum.GROUPINGVIEW.name()
				.toLowerCase()) != null) {
			grid.setData("groupingView", true);
			GroupingView view = new GroupingView();
			view.setShowGroupedColumn(false);
			view.setForceFit(true);
			String f = (String)(gxtComponentMetaNodeModel.get(GridModelEnum.GROUPINGCOLUMNID.name().toLowerCase()));
			if (f==null) {
				f="Grouping";
			}
			final String ff = f;
			grid.setData("groupingColumnId",ff);
			//分组表格中，一个分组内的表头信息
			view.setGroupRenderer(new GridGroupRenderer() {
				public String render(GroupColumnData data) {
//					String f = cm.getColumnById(data.field).getHeader();
					String l = data.models.size() == 1 ? "Item" : "Items";
					return ff + ": " + data.group + " (" + data.models.size()
							+ " " + l + ")";
					
				}
			});
			grid.setView(view);
		}
		
		//？？拖动相关
		/*if (gxtComponentMetaNodeModel.get(GridModelEnum.AllOWSELFASSOURCE
				.name().toLowerCase()) != null) {
			Boolean allowSelfAsSource = (Boolean) gxtComponentMetaNodeModel
					.get(GridModelEnum.AllOWSELFASSOURCE.name().toLowerCase());
			dropTarget.setAllowSelfAsSource(allowSelfAsSource);
		}*/
		
		return grid;
	}


	/**
	 * 
	 * 
	 * <ul>
	 * <li>方法含义：</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2012-2-12；时间：下午12:14:07</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param version 表格版本类型
	 * @param gxtComponentMetaNodeModel 控件参数
	 * @param contentPanel 存放表格的面板
	 * @return
	 * @return
	 */
	private static Grid<ModelData> createGridAndConfigureCoreAttributes(int version,
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel,ContentPanel contentPanel) {
		//gxtComponentMetaNodeModel，可能会使contentPanel可能和grid重合，混淆
		GroupingStore<ModelData> groupStore;
		ListStore<ModelData> pagingStore;
		List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
		ColumnModel cm=null;				
		// 可编辑的表格
		if (version == 1) {		
			// 表格字段集合
			ListStore<ModelData> listStore =new ListStore<ModelData>();
			//listStore = getListStore();//a example of liststore 
			final EditorGrid<ModelData> editorGrid = new EditorGrid<ModelData>(listStore, new ColumnModel(new ArrayList<ColumnConfig>()));
			configs = loadGridColumnModel(gxtComponentMetaNodeModel,configs,editorGrid,version);
			cm = new ColumnModel(configs);
			editorGrid.reconfigure(listStore, cm);
			AbstractComponetFactory.configureAbstractComponet(editorGrid, gxtComponentMetaNodeModel);		
			//getField2(configs);
			addToolBar(contentPanel, editorGrid);
			contentPanel.add(editorGrid);
			editorGrid.setLoadMask(true);

			return editorGrid;
			/*GridSelectionModel<ModelData> sm = editorGrid.getSelectionModel();
			sm.addSelectionChangedListener(new SelectionChangedListener<ModelData>() {

				@Override
				public void selectionChanged(SelectionChangedEvent<ModelData> se) {
					//editorGrid.getSelectionModel().addSelectionChangedListener(listener)
					System.err.println("????GridSelectionModel.addSelectionChangedListener...............");
					//Window.alert("GridSelectionModel.addSelectionChangedListener");
				}
			});*/
			
			//sm.sel
			/*editorGrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<ModelData>(){

				@Override
				public void selectionChanged(SelectionChangedEvent<ModelData> se) {
					
					//editorGrid.getSelectionModel().addSelectionChangedListener(listener)
					System.err.println("????GridSelectionModel.addSelectionChangedListener...............");
					//Window.alert("GridSelectionModel.addSelectionChangedListener");
																		    	
				}});*/
			//ModelData modelData = sm.getSelectedItem();
			//List<ModelData> modelDatas = sm.getSelectedItems();
			//List<ModelData> modelDatas2 =  sm.getSelection();
			
			//sm.setSelectionMode(SelectionMode.SINGLE)
			//grid.addListener(eventType, listener)
			
			
		}

		else if (version == 2) {
			// 分组表格
			//groupStore = getGroupStore(table);
			groupStore = new GroupingStore<ModelData>();
			System.err.println(configs);
			Grid<ModelData> grid = new Grid<ModelData>(groupStore, cm);
			grid.setData("gridType", 2);
			//grid.setData("groupingColumnId", XXX);其他地方实现
			contentPanel.add(grid);
			//loader.load();
			return grid;
			
		}
		else if (version == 3) {
			// 分页表格
//			pagingStore = getPaging2(gxtComponentMetaNodeModel, table);
			pagingStore =  new ListStore<ModelData>();
			final Grid<ModelData> grid = new Grid<ModelData>(pagingStore, cm);
			grid.setData("gridType", 3);
			contentPanel.add(grid);
			grid.setLoadMask(true);
			
			configurePageSizeOfPagingGrid(grid ,gxtComponentMetaNodeModel);
			//pagingLoader.load();
			
			return grid;
		}
		else if (version == 4) {
			// 可编辑分页表格
//			pagingStore = getPaging2(gxtComponentMetaNodeModel, table);
			pagingStore =  new ListStore<ModelData>();

			final EditorGrid<ModelData> grid = new EditorGrid<ModelData>(pagingStore, new ColumnModel(new ArrayList<ColumnConfig>()));
			configs = loadGridColumnModel(gxtComponentMetaNodeModel,configs,grid,version);
			configs = createShowButtonForGridColumn(configs);
			configs = createEditButtonForGridColumn(configs);
			configs = createDelteButtonForGridColumn(configs);
			cm = new ColumnModel(configs);
			grid.reconfigure(pagingStore, cm);
			AbstractComponetFactory.configureAbstractComponet(grid, gxtComponentMetaNodeModel);		
			grid.setData("gridType", 4);
			contentPanel.add(grid);
			grid.setLoadMask(true);
			
			configurePageSizeOfPagingGrid(grid ,gxtComponentMetaNodeModel);
			addToolBar(contentPanel, grid);
			contentPanel.add(grid);
			
			return grid;
		}
		else if (version == 5) {
			// 普通表格
			/*employeeStore = getListStore(table);
			*/
			Grid<ModelData> grid = new Grid<ModelData>(
					null, cm);
			grid.setData("gridType", 5);
			
			addToolBar(contentPanel, grid);

			contentPanel.add(grid);

			configureRegisterEventtypes(gxtComponentMetaNodeModel, grid, version);
			
			return grid;
		} else {
			return null;
		}

	}

	private static List<ColumnConfig> createDelteButtonForGridColumn(
			List<ColumnConfig> configs) {
		 GridCellRenderer<MyBaseModel> buttonRenderer = new GridCellRenderer<MyBaseModel>() {   
	    	  
				@Override
				public Object render(final MyBaseModel model, String property,
						ColumnData config, int rowIndex, int colIndex,
						ListStore<MyBaseModel> store, Grid<MyBaseModel> grid) {
//			          Button b = new Button((String) model.get(property), new SelectionListener<ButtonEvent>() {   
			        	Button b = new Button("删除", new SelectionListener<ButtonEvent>() {   
			            @Override  
			            public void componentSelected(ButtonEvent ce) {   
			              Info.display(model.getId(), "<ul><li>" + model.get("NAME") + "</li></ul>");   
			            }   
			          });   
			          b.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 10);   
			          b.setToolTip("Click for more information");   
			    
			          return b;
				}   
		      };  
		      ColumnConfig column=null;
		      column = new ColumnConfig();   
		      column.setId("modify");   
		      column.setHeader("删除记录");   
		      column.setWidth(100);   
		      column.setRenderer(buttonRenderer);   
		      configs.add(column);   
		      
		      return configs;
	}


	private static List<ColumnConfig> createEditButtonForGridColumn(
			List<ColumnConfig> configs) {
		 GridCellRenderer<MyBaseModel> buttonRenderer = new GridCellRenderer<MyBaseModel>() {   
	    	  
		        //private boolean init;   
				@Override
				public Object render(final MyBaseModel model, String property,
						ColumnData config, int rowIndex, int colIndex,
						ListStore<MyBaseModel> store, Grid<MyBaseModel> grid) {
					 
			    
//			          Button b = new Button((String) model.get(property), new SelectionListener<ButtonEvent>() {   
			        	Button b = new Button("修改", new SelectionListener<ButtonEvent>() {   
			            @Override  
			            public void componentSelected(ButtonEvent ce) {   
			              Info.display(model.getId(), "<ul><li>" + model.get("NAME") + "</li></ul>");   
			            }   
			          });   
			          b.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 10);   
			          b.setToolTip("Click for more information");   
			    
			          return b;
				}   
		      };  
		      ColumnConfig column=null;
		      column = new ColumnConfig();   
		      column.setId("modify");   
		      column.setHeader("修改详细信息");   
		      column.setWidth(100);   
		      column.setRenderer(buttonRenderer);   
		      configs.add(column);   
		      
		      return configs;
	}


	private static List<ColumnConfig> createShowButtonForGridColumn(
			List<ColumnConfig> configs) {
		
		 GridCellRenderer<MyBaseModel> buttonRenderer = new GridCellRenderer<MyBaseModel>() {   
	    	  
		        private boolean init;   
				@Override
				public Object render(final MyBaseModel model, String property,
						ColumnData config, int rowIndex, int colIndex,
						ListStore<MyBaseModel> store, Grid<MyBaseModel> grid) {
					if (!init) {   
			            init = true;   
			            grid.addListener(Events.ColumnResize, new Listener<GridEvent<MyBaseModel>>() {   
			    
			              public void handleEvent(GridEvent<MyBaseModel> be) {   
			                for (int i = 0; i < be.getGrid().getStore().getCount(); i++) {   
			                  if (be.getGrid().getView().getWidget(i, be.getColIndex()) != null  
			                      && be.getGrid().getView().getWidget(i, be.getColIndex()) instanceof BoxComponent) {   
			                    ((BoxComponent) be.getGrid().getView().getWidget(i, be.getColIndex())).setWidth(be.getWidth() - 10);   
			                  }   
			                }   
			              }   
			            });   
			          }   
			    
//			          Button b = new Button((String) model.get(property), new SelectionListener<ButtonEvent>() {   
			          final Button b = new Button("查看"); 
			          b.setData(ComponentMetaDataConstants.COMPONENT_ID,model.getIdentifier());
			          final String controllerMetaModelId = grid.getData(MetaDataConstants.FORM_ID).toString();
			          b.addSelectionListener(new SelectionListener<ButtonEvent>() {

			        	  @Override  
				            public void componentSelected(ButtonEvent ce) {   
				              Info.display(model.getId(), "<ul><li>" + model.get("NAME") + "</li></ul>");  
				              
					            GxtToSeamServiceParameter g1=new GxtToSeamServiceParameter(
					            		controllerMetaModelId+"_showDetail" , "findByIdentifier" );
					      		g1.setMethodArgumentsType(null);
					      		MyBaseModel baseModel=new MyBaseModel();
				    			baseModel.set(MetaDataConstants.IDENTIFIER,model.getIdentifier() );
				    			List<MyBaseModel> list = new ArrayList<MyBaseModel>();
				    			list.add(baseModel);
				    			g1.setMethodArguments2(list);
					      		
					      		
					      		ItemOfAssociateToWindow itemOfAssociateToWindow = new ItemOfAssociateToWindow();
					      		itemOfAssociateToWindow.setGxtToSeamServiceParameter(g1);
					      		EventStructureMetaModel eventStructureMetaModel = new EventStructureMetaModel();
					      		eventStructureMetaModel.setRootControllerId("desktopController");
					      		eventStructureMetaModel.setControllerId("desktopController");
					      		itemOfAssociateToWindow.setEventStructureMetaModel(eventStructureMetaModel);
					      		itemOfAssociateToWindow.setItemType(ComponentMetaDataConstants.MVC_ITEM_TYPE);
					      		itemOfAssociateToWindow.setRegisterEventType(new GxtAppEventType("0007"));
					              
				              
				              AppEvent appEvent =ComponentTrrigerTemplateUtil.createAppEvent(ce.getButton(), itemOfAssociateToWindow);
						    	  if (appEvent!=null) {								
						    		  Dispatcher.forwardEvent(appEvent);
						    	  }else {
						    		  MyLoggerUtil.printWarn(GridModuleFactory.class,
						    				  b.getClass().getName()+"【id="
												 +b.getData(ComponentMetaDataConstants.COMPONENT_ID)
												 +"】，没有 注册需要触发的AppEvents"+
												 "事件;");
						    	  }
				              
				      		}
			          });
			          b.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 10);   
			          b.setToolTip("Click for more information");   
			    
			          return b;
				}   
		      };  
		      ColumnConfig column=null;
		      column = new ColumnConfig();   
		      column.setId("show");   
		      column.setHeader("查看详细信息");   
		      column.setWidth(100);   
		      column.setRenderer(buttonRenderer);   
		      configs.add(column);   
		      
		      return configs;
	}


	private static EditorGrid<ModelData> createEditorGridAndConfigureAttributes() {
		// TODO Auto-generated method stub
		return null;
	}


	/**
	 * 
	 * 
	 * <ul>
	 * <li>方法含义：设置分页表格的每页显示记录条数，默认值为15</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2012-2-22；时间：上午11:01:04</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param grid
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static void configurePageSizeOfPagingGrid(Grid grid,
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		//分页表格，设置页面大小	pageSize	
		if (gxtComponentMetaNodeModel.get(ComponentMetaDataConstants.PAGE_SIZE) != null) {		
			Object pageSize = (Integer) gxtComponentMetaNodeModel.get(ComponentMetaDataConstants.PAGE_SIZE);
			if (pageSize instanceof Integer) {
				
				grid.setData(ComponentMetaDataConstants.PAGE_SIZE, pageSize);
			} else {
				grid.setData(ComponentMetaDataConstants.PAGE_SIZE, Integer.parseInt((String)pageSize));

			}
			
		}else {
			grid.setData(ComponentMetaDataConstants.PAGE_SIZE, 15);
		}
	}

	/**
	 * 
	 * 
	 * <ul>
	 * <li>方法含义：配置表格的字段：普通类型字段，带下拉框的字段，日期型字段</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2012-2-26；时间：下午10:41:57</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @param configs
	 * @param grid
	 * @param version
	 * @return
	 * @return
	 */
	private static List<ColumnConfig> loadGridColumnModel(GxtComponentMetaNodeModel gxtComponentMetaNodeModel,List<ColumnConfig> configs,final Grid<ModelData> grid,int version) {

		List<ComboBox<ModelData>> comboBoxs = new LinkedList<ComboBox<ModelData>>();
		ComboBox<ModelData> comboBox =null;
		if(gxtComponentMetaNodeModel.get(ComponentMetaDataConstants.CHILDREN_ITEMS)!=null){
			//添加子控件
			 List<ItemOfAssociateToWindow> list =(List<ItemOfAssociateToWindow>)gxtComponentMetaNodeModel
			 .get(ComponentMetaDataConstants.CHILDREN_ITEMS);
			
			 for(int i=0;i<list.size();i++){	
				if (list.get(i).getItemType().equals(ComponentMetaDataConstants.COMPONENT_ITEM_TYPE)) {
	//				comboBox = SimpleComboBoxFactory.createSimpleComboBox(list.get(i));
	//				comboBox = ComboBoxFactory.createComboBox(list.get(i));
					    comboBox = ComboBoxFactory.createComboBox2(list.get(i));
					    comboBoxs.add(comboBox);
				}			 
			 }		 
		 
		}
		
		//TODO 字段加载相关
		if (gxtComponentMetaNodeModel.getGridColumnConfigModels() != null) {
			Object object = gxtComponentMetaNodeModel.getGridColumnConfigModels();
			//grid.setData("columnConfigLoad", object);
			//ModelData modelData = result.getResult();
			List<GridColumnConfigModel> baseModels = (List<GridColumnConfigModel>)object;
										
			for (GridColumnConfigModel baseModel : baseModels) {
				ColumnConfig columnConfig = new ColumnConfig();
				columnConfig.setHeader((String)baseModel.get("header"));
				//设置字段是否隐藏
				if (baseModel.get("hidden")==null||!(Boolean)baseModel.get("hidden")) {
					columnConfig.setHidden(false);
				} else {
					columnConfig.setHidden(true);
				}
//				if (baseModel.get("date")!=null&&(Boolean)baseModel.get("date")) {
				/*if (baseModel.getDate()) {
					DateField dateField = new DateField();   
				    dateField.getPropertyEditor().setFormat(DateTimeFormat.getFormat("MM/dd/y"));   				    
				    columnConfig.setEditor(new CellEditor(dateField));   
				   // column.setDateTimeFormat(DateTimeFormat..getMediumDateFormat());  
				} */
				//设置字段的宽度
				columnConfig.setWidth((Integer)baseModel.get("width"));
				//设置字段的Id
				String columnConfig_id = (String)baseModel.get("id");
				columnConfig.setId(columnConfig_id);
				
				if (version==1||version==4) {
					if (comboBoxs == null||comboBoxs.size()==0) {
						columnConfig.setEditor(new CellEditor(new TextField<String>()));
					}else {
						for (ComboBox box : comboBoxs) {
							System.err.println(box.getData("id"));
							System.err.println(columnConfig_id);
							/**
							 * 由于表格中的字段为下拉框
							 * 所以需要添加两个字段（associateColumnConfig和columnConfig），而非一个
							 * associateColumnConfig对应真正的实体类例如，position中的positionType
							 * id=columnConfig_id
							 * 
							 * columnConfig，对应position中的positionTypeForShow（只是一个字符串）
							 * id=columnConfig_id+"ForShow"
							 * 并且，关联下拉框
							 */
							if (box.getData("id").equals(columnConfig_id)) {
								
								if (columnConfig_id.indexOf((String)grid.getData("id")+".") == 0) {
									columnConfig_id = columnConfig_id.substring(((String)grid.getData("id")).length()+1);
								}
								//为与ComboBox关联的ColumnConfig，添加隐藏的ColumnConfig
								ColumnConfig associateColumnConfig = new ColumnConfig();								
								associateColumnConfig.setHidden(true);
								associateColumnConfig.setHeader(columnConfig_id);
								//例如
								//position的属性-positionType，对应positionType实体类
								associateColumnConfig.setId(columnConfig_id);
								MyLoggerUtil.printError("ssssssssssssssss", columnConfig_id);
								associateColumnConfig.setWidth(100);
								associateColumnConfig.setEditor(new CellEditor(new TextField<String>()));								
//								final ComboBox<ModelData> subComboBox = new ComboBox<ModelData>();
								//final ComboBox subComboBox = new ComboBox<ModelData>();
								//subComboBox.setStore(box.getStore());
								//subComboBox.setDisplayField("id");
								//CellEditor subComboBoxCellEditor = getAssociateComboBoxCellEditor(subComboBox);
								//associateColumnConfig.setEditor(subComboBoxCellEditor);	
								//final ComboBox<ModelData> subComboBox = new ComboBox<ModelData>();																
								//关联子ComboBox
							//	assocateSubComboBox(tempComboBox, subComboBox);
								configs.add(associateColumnConfig);
								columnConfig.setId(columnConfig_id+"ForShow");
								final ComboBox<ModelData> tempComboBox = box;
								CellEditor comboBoxCellEditor = getComboBoxCellEditor(tempComboBox,grid,null);
								columnConfig.setEditor(comboBoxCellEditor);
								break;
							} else {								 
								columnConfig.setEditor(new CellEditor(new TextField<String>()));
								//throw new RuntimeException("sssssssssssssaaaaaaaaaaaaaa");
							}
						}
						
					}
					
					if (baseModel.get("date")!=null&&(Boolean)baseModel.get("date")) {
						DateField dateField = new DateField();   
					    dateField.getPropertyEditor().setFormat(DateTimeFormat.getFormat("MM/dd/y"));   				    
					    columnConfig.setEditor(new CellEditor(dateField));   
					   // column.setDateTimeFormat(DateTimeFormat..getMediumDateFormat());  
					}else if (baseModel.getDate()) {
						DateField dateField = new DateField();   
					    dateField.getPropertyEditor().setFormat(DateTimeFormat.getFormat("MM/dd/y"));   				    
					    columnConfig.setEditor(new CellEditor(dateField));   
					   // column.setDateTimeFormat(DateTimeFormat..getMediumDateFormat());  
					}
				} 
				
				configs.add(columnConfig);
			}
			
		}
		for(ColumnConfig columnConfig:configs){
			MyLoggerUtil.printError("xxxxxxxxxxxxxxxxxxxxx", columnConfig.getId()+":"+columnConfig.getHeader());
		}
		return configs;
	}

	
	// 表格的字段
	private static List<ColumnConfig> loadGridColumnModel2(GxtComponentMetaNodeModel gxtComponentMetaNodeModel,List<ColumnConfig> configs,final Grid<ModelData> grid,int version) {
		//final GxtToSeamServiceParameter gxtToSeamServiceParameter = new GxtToSeamServiceParameter();

		List<ComboBox<ModelData>> comboBoxs = new LinkedList<ComboBox<ModelData>>();
		ComboBox<ModelData> comboBox =null;
		if(gxtComponentMetaNodeModel.get(AbstractComponetModelEnum.CHILDREN.name().toLowerCase())!=null){
			//添加子控件
		 List<GxtComponentMetaNodeModel> list =(List<GxtComponentMetaNodeModel>)gxtComponentMetaNodeModel
		 .get(AbstractComponetModelEnum.CHILDREN.name().toLowerCase());
		
		 for(int i=0;i<list.size();i++)
			{			 	
//				comboBox = SimpleComboBoxFactory.createSimpleComboBox(list.get(i));
				comboBox = ComboBoxFactory.createComboBox(list.get(i));
				comboBoxs.add(comboBox);
			}			
		}
		
		//TODO 字段加载相关
		if (gxtComponentMetaNodeModel.getGridColumnConfigModels() != null) {
			Object object = gxtComponentMetaNodeModel.getGridColumnConfigModels();
			//grid.setData("columnConfigLoad", object);
			//ModelData modelData = result.getResult();
			List<BaseModel> baseModels = (List<BaseModel>)object;
										
			for (BaseModel baseModel : baseModels) {
				ColumnConfig columnConfig = new ColumnConfig();
				columnConfig.setHeader((String)baseModel.get("header"));

				if (baseModel.get("hidden")==null||!(Boolean)baseModel.get("hidden")) {
					columnConfig.setHidden(false);
				} else {
					columnConfig.setHidden(true);
				}
				
				columnConfig.setWidth((Integer)baseModel.get("width"));
				String columnConfig_id = (String)baseModel.get("id");
				columnConfig.setId(columnConfig_id);
				
				if (version==1||version==4) {
					if (comboBoxs == null||comboBoxs.size()==0) {
						columnConfig.setEditor(new CellEditor(new TextField<String>()));

					}else {
						for (ComboBox box : comboBoxs) {
//							if (box.getId().equals(columnConfig_id)) {
							if (box.getData("id").equals(columnConfig_id)) {
								
								if (columnConfig_id.indexOf((String)grid.getData("id")+".") == 0) {
									columnConfig_id = columnConfig_id.substring(((String)grid.getData("id")).length()+1);
								}
								//重新设置对应comboBox的columnConfig的Id
								//此字段用来显示BaseModel的指定属性，如NAME
								columnConfig.setId(columnConfig_id+"ForShow");

								//为与ComboBox关联的ColumnConfig，添加隐藏的ColumnConfig
								ColumnConfig associateColumnConfig = new ColumnConfig();
								associateColumnConfig.setHidden(true);
								associateColumnConfig.setHeader(columnConfig_id);
								associateColumnConfig.setId(columnConfig_id);
								associateColumnConfig.setWidth(100);
								associateColumnConfig.setEditor(new CellEditor(new TextField<String>()));
//								final ComboBox<ModelData> subComboBox = new ComboBox<ModelData>();
								//final ComboBox subComboBox = new ComboBox<ModelData>();
								//subComboBox.setStore(box.getStore());
								//subComboBox.setDisplayField("id");
								//CellEditor subComboBoxCellEditor = getAssociateComboBoxCellEditor(subComboBox);
								//associateColumnConfig.setEditor(subComboBoxCellEditor);	
								//final ComboBox<ModelData> subComboBox = new ComboBox<ModelData>();
								
								final ComboBox tempComboBox = box;
								CellEditor comboBoxCellEditor = getComboBoxCellEditor(tempComboBox,grid,null);
								columnConfig.setEditor(comboBoxCellEditor);
								
								//关联子ComboBox
							//	assocateSubComboBox(tempComboBox, subComboBox);
								configs.add(associateColumnConfig);
								break;
							} else {								 
								columnConfig.setEditor(new CellEditor(new TextField<String>()));
							}
						}
						

					}
					
					if (baseModel.get("date")!=null&&(Boolean)baseModel.get("date")) {
						DateField dateField = new DateField();   
					    dateField.getPropertyEditor().setFormat(DateTimeFormat.getFormat("MM/dd/y"));   				    
					    columnConfig.setEditor(new CellEditor(dateField));   
					   // column.setDateTimeFormat(DateTimeFormat..getMediumDateFormat());  
					} 
				} 
				
				configs.add(columnConfig);
			}
			
			

		}
		
		return configs;
	}

	
	
	
	private static List<ColumnConfig> getField2(List<ColumnConfig> configs) {
		// 实现可编辑的表格要在相应的字段上面添加celleditre的属性
		 GridCellRenderer<BaseModel> ageRender=null;
		ColumnConfig columnConfig = new ColumnConfig();
		columnConfig.setId("name");
		columnConfig.setHeader("用户22名");
		columnConfig.setWidth(100);
		columnConfig.setEditor(new CellEditor(new TextField<String>()));
		configs.add(columnConfig);
		ColumnConfig columnConfig2 = new ColumnConfig();
		columnConfig2.setId("age");
		columnConfig2.setHeader("年22龄");
		columnConfig2.setWidth(100);
		columnConfig2.setEditor(new CellEditor(new TextField<String>()));
		columnConfig2.setRenderer(ageRender);
		configs.add(columnConfig2);
		
		// 分页表格对应的字段
		
		//  configs.add(new ColumnConfig("forum", "Forum", 150)); configs.add(new
		//  ColumnConfig("username", "Username", 100)); configs.add(new
		//  ColumnConfig("subject", "Subject", 200));
		
		// 分组表格对应的字段
		
		  ColumnConfig company = new ColumnConfig("name", "Company", 60);
		  ColumnConfig price = new ColumnConfig("open", "Price", 60);
		  ColumnConfig change = new ColumnConfig("change", "Change", 60);
		  ColumnConfig industry = new ColumnConfig("industry", "Industry", 60);
		  ColumnConfig last = new ColumnConfig("date", "Last Updated", 60);
		  last.setDateTimeFormat(DateTimeFormat.getFormat("MM/dd/y"));
		  
		  configs.add(company); configs.add(price); configs.add(change);
		  configs.add(industry); configs.add(last);
		 

		
		 

		// configs =
		// GridColumnConfigFactory.createColumnConfigList(loaderNumber,
		// ageRender,service);
		
		return configs;
	}

	
	// 普通表格的后台数据
	private static ListStore<ModelData> getListStore() {
		
		/**
		 * 
		 * ServiceInvokerAsync serviceInvoker = GWT.create(ServiceInvoker.class);
		 * serviceInvoker.invokeService(className, serviceName, parameterList, callback);
		 * 传什么样的参数
		 * 调用哪个类的哪个方法
		 * 解析：
		 * 例如，想要查询人员列表，需要得到List<BaseModel>
		 * 就需要有类PersonService类，和listPerson方法
		 * 参数，暂时为空
		 * 
		 */
		/*ServiceInvokerAsync serviceInvoker = GWT.create(ServiceInvoker.class);
		serviceInvoker.invokeService("com.hy.mydesktop.server.business.PersonService", "listPerson",new AsyncCallback<List<BaseModel>>() {
			
			@Override
			public void onSuccess(List<BaseModel> result) {
				System.out.println(result+"++++++++++++++++++++++");
				List<BaseModel> bmBaseModels= new LinkedList<BaseModel>();
				for (Object object : result) {
					bmBaseModels.add((BaseModel)object);
				}
				employeeStore.add((List<BaseModel>)bmBaseModels);
			}
			
			@Override
			public void onFailure(Throwable caught) {
				System.out.println("-----------------++++++++++++++++++++++");
				caught.printStackTrace();
			}
		});*/
		/*String moduleURL = GWT.getModuleBaseURL() + "invokeService";
		
		ServiceDefTarget endpoint = (ServiceDefTarget) serviceInvoker;
		endpoint.setServiceEntryPoint(moduleURL);*/
		proxy = new RpcProxy<List<BaseModel>>() {
			@Override
			protected void load(Object loadConfig,
					AsyncCallback<List<BaseModel>> callback) {
				//serviceInvoker.invokeService("com.hy.mydesktop.server.business.PersonService", "listPerson", callback);
				//service.getBaseModle(table, callback);
			}
		};

		loader = new BaseListLoader<BaseListLoadResult<BaseModel>>(proxy);
		ListStore<ModelData> employeeStore = new ListStore<ModelData>(loader);
		// em	ployeeStore.add(TestData.getStocks());
		 GridCellRenderer<BaseModel> ageRender=null;

		ageRender = new GridCellRenderer<BaseModel>() {
			@Override
			public Object render(BaseModel model, String property,
					com.extjs.gxt.ui.client.widget.grid.ColumnData config,
					int rowIndex, int colIndex, ListStore<BaseModel> store,
					Grid<BaseModel> grid) {
				return null;
			}
		};
		employeeStore.getLoader().load();
		return employeeStore;
	}

	// 分组表格的后台数据
	private static GroupingStore<ModelData> getGroupStore(final String table) {
		RpcProxy<List<ModelData>> proxy = new RpcProxy<List<ModelData>>() {
			@Override
			protected void load(Object loadConfig,
					AsyncCallback<List<ModelData>> callback) {
				service.getGroupModle(table, callback);
			}
		};
		loader = new BaseListLoader<BaseListLoadResult<BaseModel>>(proxy);
		GroupingStore<ModelData> store = new GroupingStore<ModelData>(loader);
		// store.add(Text.getCompanies());
		store.groupBy("industry");
		store.getLoader().load();
		return store;
	}



	// 分页表格的后台数据
	/*private static ListStore<ModelData> getPaging2(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel,
			final String table) {
		RpcProxy<PagingLoadResult<ModelData>> proxy = new RpcProxy<PagingLoadResult<ModelData>>() {
			@Override
			protected void load(Object loadConfig,
					AsyncCallback<PagingLoadResult<ModelData>> callback) {
				//service.getPageGrid(table, (PagingLoadConfig) loadConfig,callback);
			}
		};

		pagingLoader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy);
		pagingLoader.setRemoteSort(true);

		ListStore<ModelData> store = new ListStore<ModelData>(pagingLoader);

		// 需要把toolbar加到面板上
		PagingToolBar toolBar = new PagingToolBar(45);  

		toolBar.bind(pagingLoader);
		toolBar.setShowToolTips(true);
		contentPanel.setBottomComponent(toolBar);
		store.getLoader().load();
		return store;
	}*/
	
	
	
	/**
	 * 
	 * 
	 * <ul>
	 * <li>方法含义：为表格，添加工具栏，包括：添加按钮、刷新按钮、删除按钮<br>
	 * 注：删除按钮，没有被启用
	 * </li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2012-2-26；时间：下午10:52:30</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param contentPanel
	 * @param grid
	 * @return
	 */
	private static void addToolBar(ContentPanel contentPanel,final Grid<ModelData> grid) {
		ToolBar toolBar = new ToolBar();   
	    //toolBar.getAriaSupport().setLabel("Grid Options");   
	    //toolBar.add(new Button());
	    Button add = new Button("Add a Row", Resources.ICONS.add(),new SelectionListener<ButtonEvent>() {   
	        @Override   
	        public void componentSelected(ButtonEvent ce) {   
//	          grid.getStore().insert(new BaseModel(), grid.getStore().getCount());   
	          grid.getStore().insert(new BaseModel(), 0);   
	         
	        }   
	    
	      });   
	    Button fefresh = new Button("Refresh the Grid", Resources.ICONS.plugin(),new SelectionListener<ButtonEvent>() {   
	        @Override   
	        public void componentSelected(ButtonEvent ce) {   
//	          grid.getStore().insert(new BaseModel(), grid.getStore().getCount());   
	          grid.getStore().getLoader().load();
	          MessageBox.alert("消息", "数据已经刷新 !", null);
	         
	        }   
	    
	      });  
	    Button delete = new Button("Delete a Row", Resources.ICONS.delete(),new SelectionListener<ButtonEvent>() {   
	        @Override   
	        public void componentSelected(ButtonEvent ce) {  
	        	 ce.getComponent().disable();   
	          /*grid.getStore().remove(grid.getStore().getAt(0));   
	          if (grid.getStore().getCount() == 0) {   
	            ce.getComponent().disable();   
	          }*/   
	        }   
	    
	      });   
	    
	    toolBar.add(add);   
	    toolBar.add(new SeparatorToolItem());   
	    toolBar.add(fefresh);   
	    //toolBar.add(delete);   
	    //toolBar.add(new SeparatorToolItem());   
	    //toolBar.add(new Button("Configure", Resources.ICONS.plugin()));   
	    contentPanel.setTopComponent(toolBar);   
	    //cp.add(grid);
	}
	
	
	private static CellEditor getComboBoxCellEditor(final ComboBox<ModelData> combo,final Grid<ModelData> grid,final ListStore<ModelData> listStore) {
		
		/*final SimpleComboBox<String> combo = new SimpleComboBox<String>();   
	    combo.setForceSelection(true);   
	    //combo.setTriggerAction(TriggerAction.ALL);   
	    combo.add("Shade");   
	    combo.add("Mostly Shady");   
	    combo.add("Sun or Shade");   
	    combo.add("Mostly Sunny");   
	    combo.add("Sunny"); */   
		final String displayFieldString = ComponentMetaDataConstants.DISPLAY_FIELD;
		//StringBuffer
	    final CellEditor editor = new CellEditor(combo) {   
	      @Override   
	      public Object preProcessValue(Object value) {   
	    	  if (value == null) {   
		        	System.out.println("preProcessValue if (value == null) value = "+value);
		          return value;   
		        }  
		        System.out.println("preProcessValue combo.findModel(value.toString())"+value);
		        for (ModelData modelData : combo.getStore().getModels()) {
					if (value.equals(modelData.get(displayFieldString))) {
						//Window.alert((String)modelData.get(displayFieldString));
						return modelData;
					}
				}  
		        return null;   
	      }   
	  
	      @Override   
	      public Object postProcessValue(Object value) {   
	    	  
	    	 
	    	  if (value == null) { 
		        //	System.out.println("postProcessValue if (value == null) value = "+value);
		          return value;   
		        }   
		        //System.out.println("postProcessValue ((ModelData) value).get(value)"+((ModelData) value).get("value"));
	    	  int rowIndex =this.row;
	    	  ModelData currentModelData = grid.getStore().getAt(rowIndex);
	    	 // grid.getStore().remove(currentModelData);
//	    	  ModelData currentModelData = listStore.getAt(rowIndex);
	    	  //currentModelData.set((String)combo.getData("id"),(ModelData)value);2222222222222222
	    	  String comboBoxId = (String)combo.getData("id");
	    	  if (comboBoxId.indexOf((String)grid.getData("id")+".") == 0) {
//				comboBoxId.substring(((String)grid.getData("id")).length()+1);
		    	  BaseModelUtil.encapsulateComponentData((BaseModel)currentModelData, comboBoxId.substring(((String)grid.getData("id")).length()+1), (BaseModel)value);
		    	  BaseModelUtil.encapsulateComponentData((BaseModel)currentModelData, comboBoxId.substring(((String)grid.getData("id")).length()+1)+".identifier", ((BaseModel)value).get("identifier").toString());

			  }else {
				  BaseModelUtil.encapsulateComponentData((BaseModel)currentModelData, (String)combo.getData("id"), (BaseModel)value);
		    	  for (String prop : ((BaseModel)value).getPropertyNames()) {
						System.err.println(prop+" :值 "+((BaseModel)value).get(prop));
		    	  		}
//		    	  BaseModelUtil.encapsulateComponentData((BaseModel)currentModelData, (String)combo.getData("id")+".identifier", ((BaseModel)value).get("identifier").toString());
		    	  BaseModelUtil.encapsulateComponentData((BaseModel)currentModelData, (String)combo.getData("id")+".identifier", ((MyBaseModel)value).getIdentifier());
			    	// System.err.println(  grid.getStore().getModels().size());;
			    	// currentModelData.set("email", (BaseModel)value);
			    	// grid.getStore().insert(currentModelData, rowIndex);
			    	// System.err.println(  grid.getStore().getModels().size());;
			  }
	    	  
	    		//Window.alert("comboBoxDataId : "+((BaseModel)value).get("identifier").toString());
	    		//Window.alert("contory.locationType : "+currentModelData.get("locationType").toString());
	    		//Window.alert("contory.locationType.identifier : "+currentModelData.get("locationType.identifier").toString());
	    	//  currentModelData.set("comBox", ((ModelData) value).get(displayFieldString));
	    		/*for (String prop : ((BaseModel)value).getPropertyNames()) {
					System.err.println(prop+" : "+((BaseModel)value).get(prop));
					Window.alert(prop+" : "+((BaseModel)value).get(prop));
	    	  		}
	    		for (String prop : grid.getStore().getAt(rowIndex).getPropertyNames()) {
					System.err.println(prop+" : "+currentModelData.get(prop));
					Window.alert(prop+" : "+currentModelData.get(prop));
	    	  }*/
		        return ((ModelData) value).get(displayFieldString);   
//		        return ((ModelData) value);   
	      }   
	    };   
	    
	   // int rowIndex = editor.row;22222222
	    return editor;
		
	}

private static CellEditor getAssociateComboBoxCellEditor(final ComboBox<ModelData> combo) {
		
		/*final SimpleComboBox<String> combo = new SimpleComboBox<String>();   
	    combo.setForceSelection(true);   
	    //combo.setTriggerAction(TriggerAction.ALL);   
	    combo.add("Shade");   
	    combo.add("Mostly Shady");   
	    combo.add("Sun or Shade");   
	    combo.add("Mostly Sunny");   
	    combo.add("Sunny"); */  
	    
	  
	    CellEditor editor = new CellEditor(combo) {   
	      @Override   
	      public Object preProcessValue(Object value) {   
	    	  if (value == null) {   
		        	System.out.println("preProcessValue if (value == null) value = "+value);
		          return value;   
		        }  
		        System.out.println("preProcessValue combo.findModel(value.toString())"+value);
		        for (ModelData modelData : combo.getStore().getModels()) {
					if (value.equals(modelData.get("NAME"))) {
						return modelData;
					}
				}  
		        return null;   
	      }   
	  
	      @Override   
	      public Object postProcessValue(Object value) {   
	    	  if (value == null) { 
		        //	System.out.println("postProcessValue if (value == null) value = "+value);
		          return value;   
		        }   
		        //System.out.println("postProcessValue ((ModelData) value).get(value)"+((ModelData) value).get("value"));
	    	 // this.ge
		        return ((ModelData) value).get("NAME");   
	      }   
	    };   
	    
	    return editor;
		
	}


	
	private static void assocateSubComboBox(ComboBox<ModelData> combo ,final ComboBox<ModelData> subComboBox) {
		combo.addSelectionChangedListener(new SelectionChangedListener<ModelData>() {
					
					@Override
					public void selectionChanged(SelectionChangedEvent<ModelData> se) {
						
						ModelData modelData =se.getSelectedItem();
						System.err.println("id :"+modelData.get("id")+" name :" +modelData.get("NAME"));
						for (String str : modelData.getPropertyNames()) {
							System.err.println(str);
						}
						subComboBox.select(2);
						/*//com.google.gwt.user.client.Window.alert(se.getSelectedItem().get("name").toString());
						List<ModelData> allChildren = null;
						
						allChildren = subComboBox.getData("store");
						if (allChildren==null) {
							System.err.println("subComboBox.getData(store) 为空");
						}
						subComboBox.getStore().removeAll();
						subComboBox.getStore().add(allChildren);
						List<ModelData> currentChildren =
							subComboBox.getStore().findModels("parent", se.getSelectedItem().get("name").toString());
						subComboBox.getStore().add(allChildren);
						for (ModelData modelData : currentChildren) {
								System.err.println(modelData.get("name"));
								
						}
						
						subComboBox.getStore().removeAll();
						subComboBox.getStore().add(currentChildren);*/
						
					}
				});
	}




	private static void configureRegisterEventtypes(GxtComponentMetaNodeModel gxtComponentMetaNodeModel,final Grid<ModelData> grid,int version) {
		
		if(gxtComponentMetaNodeModel.get(GridModelEnum.REGISTEREVENTTYPES.name().toLowerCase())!=null){
					
					final Map<String,Object> appEventCodes = gxtComponentMetaNodeModel.get(ShortcutModelEnum.REGISTEREVENTTYPES.name().toLowerCase());
					for ( final String code : appEventCodes.keySet()) {
						Integer i = Integer.valueOf(code);
						switch (i) {
				            case 1://Integer.valueOf("0001")
				            	//shortcutController.addRegisterEventType(AppEvents.Login);
				            	
				                break;
				            case 2://Integer.valueOf("0002")
				            	//shortcutController.addRegisterEventType(AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER);	
				                break;
				            
				            case 302://Integer.valueOf("0003")
				            	
				                break;
				           
				            case 10://Integer.valueOf("0003")
				            	/**
				            	 * BUTTON_ONCLICK_NEW或者，子程序初始化事件
				            	 * 然后窗口接受，并响应这个事件
				            	 * 根据得到的gxtComponentMetaModel，
				            	 * 加载树状控制器
				            	 * 然后，再向这树状控制器，发生事件（？），
				            	 * 初始化控制器对应的窗口或程序
				            	 */
				            	/**
				            	 * BUTTON_ONCLICK_NEW或者，子程序初始化事件，应该包含什么信息
				            	 * 1、哪个控制器响应这个事件
				            	 * 2
				            	 * gxtComponentMetaModel包含
				            	 */
				            	/**
				            	 * 如何初始化子程序
				            	 * 1、通过Rpc，加载控制器
				            	 * 2、Dispatcher.get().addController，添加此控制器
				            	 * 3、初始化，此控制器对应的窗口
				            	 * 4、在父窗口中，添加此子窗口 window.setData("children",List<Window>);
				            	 */
				            	grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<ModelData>(){

				    				@Override
				    				public void selectionChanged(SelectionChangedEvent<ModelData> se) {
				    					
				    					//editorGrid.getSelectionModel().addSelectionChangedListener(listener)
				    					System.err.println("????GridSelectionModel.addSelectionChangedListener...............");
				    					//Window.alert("GridSelectionModel.addSelectionChangedListener");
				    					
				    					;
				    					Map<String, Object> data = (Map<String, Object>)appEventCodes.get(code);
				            			//gxtToSeamServiceParameter通过data.get("gxtToSeamServiceParameter")获得
				            			//data.put("gxtToSeamServiceParameter", grid.getData("gxtToSeamServiceParameter"));
				            			data.put("dataObjectId",se.getSelectedItem().get("identifier"));
				    			    	EventStructureMetaModel eventstructuremetamodel = 
				    							 (EventStructureMetaModel)data.get("eventstructuremetamodel");
				    			    	System.out.println("Shortcut触发AppEvents.DESKTOP_SUB_APPLICATION_INIT事件:"
				    			    			 +" " +eventstructuremetamodel.getControllerId()
				    			    			 +" " +eventstructuremetamodel.getResponseModeId());
				    			    	//button.setData("0010",true);
//				    			    	Dispatcher.forwardEvent(AppEvents.DESKTOP_SUB_APPLICATION_INIT,data);
				    			    	Dispatcher.forwardEvent(AppEvents.DESKTOP_SUB_APPLICATION_AND_DATA_INIT,data);
				    			    	
				    			    	/**
				    			    	 * 对应的窗口控制器id----它实际对应的方法---------通过当前窗口获得
				    			    	 * 当前某行数据id-------------
				    			    	 * 
				    			    	 * 
				    			    	 * 这两项都需要通过事件发送
				    			    	 */
				    			    	
				    				}});
				                break;
				            case 14://Integer.valueOf("0003")
				            	/**
				            	 * BUTTON_ONCLICK_NEW或者，子程序初始化事件
				            	 * 然后窗口接受，并响应这个事件
				            	 * 根据得到的gxtComponentMetaModel，
				            	 * 加载树状控制器
				            	 * 然后，再向这树状控制器，发生事件（？），
				            	 * 初始化控制器对应的窗口或程序
				            	 */
				            	/**
				            	 * BUTTON_ONCLICK_NEW或者，子程序初始化事件，应该包含什么信息
				            	 * 1、哪个控制器响应这个事件
				            	 * 2
				            	 * gxtComponentMetaModel包含
				            	 */
				            	/**
				            	 * 如何初始化子程序
				            	 * 1、通过Rpc，加载控制器
				            	 * 2、Dispatcher.get().addController，添加此控制器
				            	 * 3、初始化，此控制器对应的窗口
				            	 * 4、在父窗口中，添加此子窗口 window.setData("children",List<Window>);
				            	 */
				            	grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<ModelData>(){

				    				@Override
				    				public void selectionChanged(SelectionChangedEvent<ModelData> se) {
				    					
				    					//editorGrid.getSelectionModel().addSelectionChangedListener(listener)
				    					System.err.println("????GridSelectionModel.addSelectionChangedListener...............");
				    					//Window.alert("GridSelectionModel.addSelectionChangedListener");
				    					
				    					;
				    					Map<String, Object> data = (Map<String, Object>)appEventCodes.get(code);
				            			//gxtToSeamServiceParameter通过data.get("gxtToSeamServiceParameter")获得
				            			//data.put("gxtToSeamServiceParameter", grid.getData("gxtToSeamServiceParameter"));
				            			data.put("dataObjectId",se.getSelectedItem().get("identifier"));
				    			    	EventStructureMetaModel eventstructuremetamodel = 
				    							 (EventStructureMetaModel)data.get("eventstructuremetamodel");
				    			    	System.out.println("Shortcut触发AppEvents.DESKTOP_SUB_APPLICATION_INIT事件:"
				    			    			 +" " +eventstructuremetamodel.getControllerId()
				    			    			 +" " +eventstructuremetamodel.getResponseModeId());
				    			    	//button.setData("0010",true);
				    			    	Dispatcher.forwardEvent(AppEvents.DESKTOP_SUB_APPLICATION_AND_DATA_INIT,data);
				    			    	
				    			    	/**
				    			    	 * 对应的窗口控制器id----它实际对应的方法---------通过当前窗口获得
				    			    	 * 当前某行数据id-------------
				    			    	 * 
				    			    	 * 
				    			    	 * 这两项都需要通过事件发送
				    			    	 */
				    			    	
				    				}});
				                break;
				           
			           		           
				            default:
				                break;
				        }
					}
				}
	}

}
